package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.CustomLog;
import com.ruoyi.system.domain.Dept;
import com.ruoyi.system.service.ICustomLogService;
import com.ruoyi.system.service.IDeptService;
import com.ruoyi.system.service.IDeptidOlddeptidService;
import com.ruoyi.system.service.SendSmsService;
import com.ruoyi.web.controller.tool.JsonResult;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.spring.web.json.Json;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 短信发送Controller
 * 
 * @author daiyi
 * @date 2023-05-10
 */
@Controller
@RequestMapping("/system/sendsms")
public class SendSmsController extends BaseController
{
    @Autowired
    private static SendSmsService sendSmsService;

    @Autowired
    private IDeptService deptService;

    @Autowired
    private IDeptidOlddeptidService deptidOlddeptidService;

    /**
     * 人口库核查短信
     */
    @PostMapping( "/renkoukuhecha/sendone")
    @ResponseBody
    public JsonResult<?> renkoukuhechasendone(@RequestParam("deptid")String ppDeptId){
        try{

            Dept mmDept = deptService.selectDeptById(deptidOlddeptidService.DeptIdToOldDeptId(ppDeptId));
            if (mmDept==null){
                return JsonResult.getErrorResult("该单位不存在");
            }
            String mmShoujihaoma = mmDept.getFuzerenshoujihaoma()==null?"":mmDept.getFuzerenshoujihaoma();
            if (mmShoujihaoma.equals("")){
                return JsonResult.getErrorResult("该单位未填写负责人手机号码");
            }

            Map<String,Object> mmMap = new HashMap<>();

            boolean ok = sendSmsService.sendZDY(mmShoujihaoma,"SMS_460770854",mmMap);

            return ok==true?JsonResult.getSuccessResult("发送成功"):JsonResult.getErrorResult("发送失败");

        } catch (Exception e) {
            logger.error("sendsms -> /renkoukuhecha/sendone: "+e.getMessage());
            return JsonResult.getErrorResult("人口库核查失败");
        }
    }


}
